<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="./v4.6.5-dist/ol.css">
    <title>Document</title>
    <style>
        html, body {
            margin: 0;
            padding: 0;
        }
    </style>
    <script src="./v4.6.5-dist/ol.js"></script>
</head>
<body>
<div id="map">

</div>
<script>
    const blur = document.getElementById('blur');
    const radius = document.getElementById('radius');

    const vector = new HeatmapLayer({
        source: new VectorSource({
            url: 'data/kml/2012_Earthquakes_Mag5.kml',
            format: new KML({
                extractStyles: false
            })
        }),
        blur: parseInt(blur.value, 10),
        radius: parseInt(radius.value, 10)
    });

    vector.getSource().on('addfeature', function(event) {
        // 2012_Earthquakes_Mag5.kml stores the magnitude of each earthquake in a
        // standards-violating <magnitude> tag in each Placemark.  We extract it from
        // the Placemark's name instead.
        const name = event.feature.get('name');
        const magnitude = parseFloat(name.substr(2));
        event.feature.set('weight', magnitude - 5);
    });

    const raster = new TileLayer({
        source: new Stamen({
            layer: 'toner'
        })
    });

    const map = new Map({
        layers: [raster, vector],
        target: 'map',
        view: new View({
            center: [0, 0],
            zoom: 2
        })
    });


    blur.addEventListener('input', function() {
        vector.setBlur(parseInt(blur.value, 10));
    });

    radius.addEventListener('input', function() {
        vector.setRadius(parseInt(radius.value, 10));
    });
</script>
</body>
</html>